]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st-widget: Introduce widget resource scale
authorJonas Ådahl <jadahl@gmail.com>
Thu, 11 May 2017 04:30:04 +0000 (06:30 +0200)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 1 Mar 2019 17:12:52 +0000 (17:12 +0000)
This commit makes StWidget manage the scale of which its associated
resources should be multiplied with. The resource scale is calculated
by clutter, and is retrieved by clutter_actor_get_resource_scale(). Due
to the resource scale not always being available, the getter may fail,
and the actual widget that draws the content will have to deal with
this situation.

As the resource scale depends on where on the stage the widget is drawn,
the resource scale will in general be available once the widget is
mapped.

https://bugzilla.gnome.org/show_bug.cgi?id=765011

src/st/st-widget.c
src/st/st-widget.h

index d12dbb3e285fe7d878830b27016a019cd0f33232..78053804b2d57fdda5734e406ba1da14260a3572 100644 (file)
@@ -121,6 +121,7 @@ enum
 {
   STYLE_CHANGED,
   POPUP_MENU,
+  RESOURCE_SCALE_CHANGED,
 
   LAST_SIGNAL
 };
@@ -452,6 +453,7 @@ static void
 st_widget_parent_set (ClutterActor *widget,
                       ClutterActor *old_parent)
 {
+  StWidget *self = ST_WIDGET (widget);
   ClutterActorClass *parent_class;
   ClutterActor *new_parent;
 
@@ -463,7 +465,7 @@ st_widget_parent_set (ClutterActor *widget,
 
   /* don't send the style changed signal if we no longer have a parent actor */
   if (new_parent)
-    st_widget_style_changed (ST_WIDGET (widget));
+    st_widget_style_changed (self);
 }
 
 static void
@@ -1019,6 +1021,21 @@ st_widget_class_init (StWidgetClass *klass)
                   G_STRUCT_OFFSET (StWidgetClass, popup_menu),
                   NULL, NULL, NULL,
                   G_TYPE_NONE, 0);
+
+  /**
+   * StWidget::resource-scale-changed:
+   * @widget: the #StWidget
+   *
+   * Emitted when the paint scale that the widget will be painted as
+   * changed.
+   */
+  signals[RESOURCE_SCALE_CHANGED] =
+    g_signal_new ("resource-scale-changed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (StWidgetClass, resource_scale_changed),
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
 }
 
 /**
@@ -1448,6 +1465,23 @@ st_widget_get_style (StWidget *actor)
   return ST_WIDGET_PRIVATE (actor)->inline_style;
 }
 
+/**
+ * st_widget_get_resource_scale:
+ * @widget: A #StWidget
+ * @resource_scale: (out): return location for the resource scale
+ *
+ * Retrieves the resource scale for this #StWidget, if available.
+ *
+ * The resource scale refers to the scale the actor should use for its resources.
+ */
+gboolean
+st_widget_get_resource_scale (StWidget *widget,
+                              float    *resource_scale)
+{
+  return clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget),
+                                           resource_scale);
+}
+
 static void
 st_widget_name_notify (StWidget   *widget,
                        GParamSpec *pspec,
@@ -1456,6 +1490,14 @@ st_widget_name_notify (StWidget   *widget,
   st_widget_style_changed (widget);
 }
 
+static void
+st_widget_resource_scale_notify (StWidget   *widget,
+                                 GParamSpec *pspec,
+                                 gpointer    data)
+{
+  g_signal_emit (widget, signals[RESOURCE_SCALE_CHANGED], 0);
+}
+
 static void
 st_widget_reactive_notify (StWidget   *widget,
                            GParamSpec *pspec,
@@ -1536,6 +1578,7 @@ st_widget_init (StWidget *actor)
 
   /* connect style changed */
   g_signal_connect (actor, "notify::name", G_CALLBACK (st_widget_name_notify), NULL);
+  g_signal_connect (actor, "notify::resource-scale", G_CALLBACK (st_widget_resource_scale_notify), NULL);
   g_signal_connect (actor, "notify::reactive", G_CALLBACK (st_widget_reactive_notify), NULL);
 
   g_signal_connect (actor, "notify::first-child", G_CALLBACK (st_widget_first_child_notify), NULL);
index 36a6325674db68e8e7adea53e4e786c90c550b25..7c76c51368ec82b62a5101c5d8f461aa2e813359 100644 (file)
@@ -63,6 +63,7 @@ struct _StWidgetClass
   /* signals */
   void     (* style_changed)       (StWidget         *self);
   void     (* popup_menu)          (StWidget         *self);
+  void     (* resource_scale_changed) (StWidget         *self);
 
   /* vfuncs */
 
@@ -137,6 +138,8 @@ StThemeNode *         st_widget_peek_theme_node           (StWidget        *widg
 
 GList *               st_widget_get_focus_chain           (StWidget        *widget);
 void                  st_widget_paint_background          (StWidget        *widget);
+gboolean              st_widget_get_resource_scale        (StWidget        *widget,
+                                                           float           *resource_scale);
 
 /* debug methods */
 char  *st_describe_actor       (ClutterActor *actor);